<?php

namespace app\admin\model;

use think\Model;


class Student extends Model
{

    

    

    // 表名
    protected $name = 'student';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'grade_data_text',
        'tag_text'
    ];
    

    
    public function getGradeDataList()
    {
        return ['1' => __('Grade_data 1'), '2' => __('Grade_data 2'), '3' => __('Grade_data 3'), '4' => __('Grade_data 4')];
    }

    public function getTagList()
    {
        return ['1' => __('Tag 1'), '2' => __('Tag 2'), '3' => __('Tag 3'), '4' => __('Tag 4'), '5' => __('Tag 5')];
    }


    public function getGradeDataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['grade_data']) ? $data['grade_data'] : '');
        $list = $this->getGradeDataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTagTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['tag']) ? $data['tag'] : '');
        $list = $this->getTagList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function grade()
    {
        return $this->belongsTo('Grade', 'grade_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function gclass()
    {
        return $this->belongsTo('Gclass', 'class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function school()
    {
        return $this->belongsTo('School', 'school_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function subject()
    {
        return $this->belongsTo('Subject', 'subject_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
